package com.johnny.bootlaunch.config;

import com.johnny.bootlaunch.exception.ParamValidateException;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.Set;

public class ParamValidator {
    Validator validator;

    public ParamValidator(Validator paramValidator){this.validator = paramValidator;}

    public final<T> void customValidator(T objects,Class<?>... groups){
        Set<ConstraintViolation<T>>  violationSet = validator.validate(objects,groups);
        for(ConstraintViolation<T> model:violationSet){
            throw new ParamValidateException(model.getMessage());
        }
    }
    
}
